package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymatou.iapi.trading.ordersync.parameter.Delivery;
import com.ymatou.iapi.trading.ordersync.parameter.Fund;
import com.ymatou.iapi.trading.ordersync.parameter.OrderBean;
import com.ymatou.iapi.trading.ordersync.parameter.Product;
import com.ymatou.iapi.trading.ordersync.parameter.Refund;
import com.ymatou.iapi.trading.ordersync.parameter.StatusLog;
import com.ymatou.iapi.trading.ordersync.parameter.po.SubProduct;
import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.utils.EnvSetup;

/************************************************************************************
 * @File name :DefaultWapper.java
 * @Author : zhouyi
 * @Date : 2015年6月1日
 * @Copyright : 洋码头
 ************************************************************************************/
public class CommandQueryWapper {
	SqlManager manage;

	public CommandQueryWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}

	/**
	 * @param orderId
	 * @return See YmtProductsInActivityWapper#selectNewActiveProductInfo
	 * @see CommandQueryWapper#selectNewActiveProductInfo
	 * @throws InterruptedException
	 */
	public OrderBean selectAllOrderInfoByOrderId(long orderId)
			throws InterruptedException {

		OrderBean order = new OrderBean();

		Map m = new HashMap();
		m.put("orderId", orderId);

		List<?> list = manage.getSelectResults(
				"com.ymttest.database.mapping.CommandQueryMapper.getAll", m);

		List<OrderBean> lo = (List<OrderBean>) list.get(0);
		List<Fund> lf = (List<Fund>) list.get(1);
		List<Product> lp = (List<Product>) list.get(2);
		List<StatusLog> lsl = (List<StatusLog>) list.get(3);
		List<Refund> lr = (List<Refund>) list.get(4);
		List<Delivery> ld = (List<Delivery>) list.get(5);
		List<Integer> lBiz = (List<Integer>) list.get(6);
		List<String> BillCode = (List<String>) list.get(7);
		List<SubProduct> OrderInfoSubPo = (List<SubProduct>) list.get(8);

		order = lo.get(0);
		Fund f = lf.get(0);

		order.setFund(f);
		order.setProducts(lp);
		order.setStatusLog(lsl);
		order.setRefunds(lr);
		order.setSubProducts(OrderInfoSubPo);

		Delivery dlv = null;

		if (ld.size() > 0) {
			dlv = ld.get(0);
		}

		if (lBiz.size() > 0) {
			if (dlv == null) {
				dlv = new Delivery();
			}
			dlv.setBizType(lBiz);
		}
		if (BillCode.size() > 0) {
			if (dlv == null) {
				dlv = new Delivery();

			}
			dlv.setBillCode(BillCode);
		}
		order.setDelivery(dlv);

		return order;
	}
	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	public static void main(String args[]) throws InterruptedException {
		CommandQueryWapper database = new CommandQueryWapper();

		HashMap m = new HashMap();
		m.put("excludeBlacklistConsumers", false);
		m.put("turnover", true);
		m.put("sellerId", 288484);
		m.put("orderId", 112464486);
		// m.put("timeType", 101);
		/*
		 * m.put("beginTime", 1111); m.put("endTime", 222);
		 */

		/*
		 * List<Map> dbOrderList=database.selectOrderBySeller(m);
		 */
		// Logger.debug(new DefaultWapper().getOrderFlows(m));
		// database.selectSettlementInvoice("top 1 *", null, "1=1");
		OrderBean orderBean = database.selectAllOrderInfoByOrderId(112501707);
		Logger.info("orderBean:" + orderBean);
		Logger.info("orderBean:" + orderBean.getId());

	}
}
